package com.ruoyi.user.mapper;

import com.ruoyi.user.domain.User;
import com.ruoyi.user.vo.IndexOrderDateResponseVo;
import com.ruoyi.user.vo.IndexResponseVo;
import com.ruoyi.user.vo.IndexUserDateResponseVo;
import com.ruoyi.user.vo.IndexVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.math.BigDecimal;
import java.util.List;

/**
 * 客户管理Mapper接口
 *
 * @author ruoyi
 * @date 2025-04-10
 */
public interface UserMapper {
    /**
     * 查询客户管理
     *
     * @param id 客户管理主键
     * @return 客户管理
     */
    public User selectUserById(Long id);

    /**
     * 查询客户管理列表
     *
     * @param user 客户管理
     * @return 客户管理集合
     */
    public List<User> selectUserList(User user);

    /**
     * 新增客户管理
     *
     * @param user 客户管理
     * @return 结果
     */
    public int insertUser(User user);

    /**
     * 修改客户管理
     *
     * @param user 客户管理
     * @return 结果
     */
    public int updateUser(User user);

    /**
     * 删除客户管理
     *
     * @param id 客户管理主键
     * @return 结果
     */
    public int deleteUserById(Long id);

    /**
     * 批量删除客户管理
     *
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteUserByIds(Long[] ids);

    @Update("update t_user set is_delete = #{isDetele} where id = #{id}")
    Integer updateIsDelete(@Param("id") Long id, @Param("isDetele") Integer isDetele);

    @Update("update t_user set user_balance = user_balance+#{amount} where id = #{userId}")
    Integer addBalance(@Param("userId") Long userId, @Param("amount") BigDecimal amount);

    @Select("select count(*) from t_user_item_order where user_id = #{userId} and order_type = 0")
    Integer selectUserPlaceOrderCount(@Param("userId") Long userId);

    BigDecimal selectConsume(@Param("userId") Long userId, @Param("type") Integer type);

    BigDecimal selectUpgradeConsume(@Param("userId") Long userId, @Param("type") Integer type);

    BigDecimal selectRefund(@Param("userId") Long userId, @Param("type") Integer type);

    String selectVipName(@Param("userId") Long userId);

    @Select("SELECT group_concat(u.label_name ORDER BY find_in_set( u.label_name, t.user_label )) labelName FROM `t_user` t INNER JOIN `t_user_label` u ON find_in_set( u.id, t.user_label )> 0 WHERE t.id = #{userId} GROUP BY t.id")
    String selectUserLabeList(@Param("userId") Long userId);

    void setUserLabelName(List<String> collect);

    @Select("select technician_name from t_technician where id = #{tid}")
    String selectTName(@Param("tid") Long tid);

    @Select("select user_nike_name from t_user where id = #{userId}")
    String selectUserName(@Param("userId") Long userId);


    BigDecimal selectSalesmanIncome(IndexVo requestVo);

    BigDecimal selectChannelIncome(IndexVo requestVo);

    BigDecimal selectBrokerIncome(IndexVo requestVo);

    IndexResponseVo selectOrderData(IndexVo requestVo);
    IndexResponseVo selectUserData(IndexVo requestVo);
    IndexResponseVo selectBlackUserData(IndexVo requestVo);

    IndexResponseVo selectBellOrderData(IndexVo requestVo);
    IndexResponseVo selectRefundOrderData(IndexVo requestVo);

    User selectPartner(@Param("partnerTel") String partnerTel);

    @Select("SELECT count(*) count FROM `t_user_item_order` group by user_id  having count =1 ")
    List<Long> selectConsumedOneCount();


    @Select("SELECT ifnull(count(*),0) count from t_user tu LEFT JOIN t_user_item_order tuio on tu.id = tuio.user_id where tuio.user_id is null")
    Integer selectNotConsumedCount();

    @Select("select ifnull(count(*),0) from t_user")
    Integer selectCount();

    @Select("select ifnull(count(*),0) from t_user where is_delete = 1")
    Integer selectBlackUserCount();

    //List<IndexUserDateResponseVo> indexUserDate(IndexVo indexVo);
    List<IndexUserDateResponseVo> indexUser(@Param("startDate") String startDate,@Param("endDate") String endDate);

    List<IndexOrderDateResponseVo> selectOrderDate(IndexVo indexVo);
    List<IndexOrderDateResponseVo> selectRefundOrderDate(IndexVo indexVo);


    List<IndexOrderDateResponseVo> selectYearOrderDate(IndexVo indexVo);
    List<IndexOrderDateResponseVo> test(@Param("startDate") String startDate,@Param("endDate") String endDate);

    List<IndexOrderDateResponseVo> selectYearRefundOrderDate(IndexVo indexVo);
    List<IndexOrderDateResponseVo> selectRefundOrder(@Param("startDate") String startDate,@Param("endDate") String endDate);


}
